/******************************************************************
 *
 *    Java Lib For JavaWeb, Powered By Shenzhen WEI YI KE JI .
 *
 *    Copyright (c) 2017-2027 Digital Telemedia Co.,Ltd
 *    http://www.d-telemedia.com/
 *
 *    Package:     com.theyeasy.dvmini.service.impl
 *
 *    Filename:    RemarksServiceImpl.java
 *
 *    Description: TODO(用一句话描述该文件做什么)
 *
 *    Copyright:   Copyright (c) 2017-2027
 *
 *    Company:     Theyeasy Telemedia Co.,Ltd
 *
 *    @author:     hm
 *
 *    @version:    1.0.0
 *
 *    Create at:   2017年11月28日 上午10:54:31
 *
 *    Revision:
 *
 *    2017年11月28日 上午10:54:31
 *        - first revision
 *
 *****************************************************************/
package com.theyeasy.dvmini.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.theyeasy.dvmini.dao.RemarksDao;
import com.theyeasy.dvmini.model.Remarks;
import com.theyeasy.dvmini.service.RemarksService;
import com.theyeasy.dvmini.util.CommonUtil;
import com.theyeasy.dvmini.util.PageResults;

/**
 * @ClassName RemarksServiceImpl
 * @Description TODO(这里用一句话描述这个类的作用)
 * @author hm
 * @Date 2017年11月28日 上午10:54:31
 * @version 1.0.0
 */
@Service
public class RemarksServiceImpl implements RemarksService {

    @Autowired
    RemarksDao remarkDao;
    
    /* (非 Javadoc)
     * Description:
     * @see com.theyeasy.dvmini.service.RemarksService#getRemarksList(java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.String)
     */
    @Override
    public PageResults<Remarks> getRemarksList(Integer page, Integer pagesize, Integer estateid, String keyword) {
        PageResults<Remarks> pageResults=new PageResults<>();
        List<Remarks> list=remarkDao.getRemarksList((page-1)*pagesize,pagesize, estateid, keyword);
        int total=remarkDao.getRemarksCount(estateid, keyword);
        pageResults.setPage(page);
        pageResults.setPageSize(pagesize);
        pageResults.setRows(list);
        pageResults.setTotal(total);
        return pageResults;
    }

    /* (非 Javadoc)
     * Description:
     * @see com.theyeasy.dvmini.service.RemarksService#addRemark(java.lang.Integer, java.lang.String, java.lang.Integer)
     */
    @Override
    public String addRemark(Integer fansid, String content, Integer estateid) {
        Remarks remark=new Remarks();
        remark.setContent(content);
        remark.setFansid(fansid);
        remark.setEstateid(estateid);
        remark.setCreatedtime(CommonUtil.getTime());
        remark.setDeleted(false);
        int row=remarkDao.insertSelective(remark);
        return row>0?"ok":"添加失败，数据异常";
    }

    /* (非 Javadoc)
     * Description:
     * @see com.theyeasy.dvmini.service.RemarksService#deleteRemark(java.lang.Integer)
     */
    @Override
    public String deleteRemark(Integer id) {
        // TODO Auto-generated method stub
        Remarks remark=remarkDao.selectByPrimaryKey(id);
        remark.setDeleted(true);
        int row=remarkDao.updateByPrimaryKeySelective(remark);
        return row>0?"ok":"删除失败，数据异常";
    }

}
